import pointOrderApi from '../../api/pointOrderApi'
import pointApi from '../../api/pointApi'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    address: '',
    content: '',
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },


  chooseAddress() {

    wx.chooseAddress({
      success: (res) => {
        console.log(res.userName)
        console.log(res.postalCode)
        console.log(res.provinceName)
        console.log(res.cityName)
        console.log(res.countyName)
        console.log(res.detailInfo)
        console.log(res.nationalCode)
        console.log(res.telNumber)

        this.setData({
          address: res
        })
      }
    })
  },

  inputContent(e) {

    this.setData({
      content: e.detail.value
    })
  },



  async submit() {
    if (!this.data.address) {
      wx.showToast({
        title: '请选择收货地址',
        icon: 'none'
      })
      return
    }
    let orderItem = wx.getStorageSync('orderItem')
    wx.showLoading()
    let res = await pointApi.exchange({
      openid: wx.getStorageSync('openid'),
      goodsId: orderItem.goodsId,
      orderItem: orderItem,
      address: this.data.address,
      content: this.data.content
    })
    wx.hideLoading()
    if(res.result.code != 200){
      wx.showToast({
        title: res.result.msg,
        icon: 'none'
      })
     
      return
    }
    
    
    wx.redirectTo({
      url: '/pointShop/pointOrderDetail/pointOrderDetail?_id=' + res.result.data,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})